(function() {
  'use strict';

  angular
    .module('hp')
    .controller('PlayCodeController', PlayCodeController);

  /** @ngInject */
  function PlayCodeController($log,toastr,$scope,$state,$stateParams,PlayCodeService,$rootScope,$uibModal) {
    var vm = this;
    vm.list = [];
    vm.show = show;
    // vm.code = 'las;dfjlsahdfwoiaehfoaf'

    PlayCodeService.query({body:{}}).$promise.then(function(data){
        // $rootScope.$broadcast('loading:finished','');
        var c = data || {};
        var code = c.head.errorCode + '';
        switch (code) {
            case '200':
                vm.list = c.body?c.body.list?c.body.list:[]:[];
                break;
            case '401':
            case '403':
                $rootScope.$broadcast('event:auth-require',{});
                // $state.go('login')
                break;
            default:
                toastr.info('' + c.head.errorMsg)
        }
    },function(err){
        toastr.info('服务器正忙:'+err)
        $log.debug(err);
    });
    
    function show(data){
        $uibModal.open({
            animation: true,
            ariaLabelledBy: 'modal-title',
            ariaDescribedBy: 'modal-body',
            templateUrl: 'modal.html',
            size: 'sm',
            controller: function($scope,$uibModalInstance) {
                $scope.name = 'top';  
                $scope.code = data;
                $scope.ok = function(){
                    $uibModalInstance.dismiss();
                }
            }
        });

    }

    }


})();
